package cn.thoughtworks.school.usercenter.entities;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;

@Entity
@DynamicInsert
@Table(name = "userDetail")
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class UserDetail {

    @Id
    @Column(name = "userId")
    private Long userId;

    @Column
    private String school;

    @Column
    private String name;

    @Column
    private String major;

    @Column
    private String degree;

    @Column
    private String gender;

    @Column
    private String schoolProvince;

    @Column
    private String schoolCity;

    @Column
    private String entranceYear;
    private String wechat;
    private String qq;
    private Long currentOrganizationId;

    public UserDetail(Long id, String username, Long organizationId) {
        this.userId = id;
        this.name = username;
        this.currentOrganizationId = organizationId;
    }

    public static List<UserDetail> buildUsersDetail(List<User> users, Long organizationId) {
        return users.stream().map(user -> new UserDetail(user.getId(), user.getUsername(), organizationId))
            .collect(Collectors.toList());
    }
}
